//
//  TKL_BeautyDetailVC.m
//  TKL_EnPro
//
//  Created by 雅恩三河科技 on 2018/12/7.
//  Copyright © 2018年 MrZhang. All rights reserved.
//

//
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//                  \./                  \\`.
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
//
//

#import "TKL_BeautyDetailVC.h"
#import "TKL_BeautyDetailViewModel.h"
@interface TKL_BeautyDetailVC ()
@property(nonatomic,strong)TKL_BeautyDetailViewModel* viewModel;
@property(nonatomic,strong)UIButton* btomBtn;
@end

@implementation TKL_BeautyDetailVC
#pragma mark - getter and setter
-(UIButton *)btomBtn
{
    if (!_btomBtn)
    {
        @WeakSelf;
        _btomBtn = [[UIButton alloc]init];
        _btomBtn.width=WFCGFloatX(375);
        _btomBtn.height=WFCGFloatY(45);
        _btomBtn.x=WFCGFloatX(0);
        _btomBtn.y=SCREEN_HEIGHT-[self bottomShelterHeight]-WFCGFloatY(45);;
        [_btomBtn setEnlargeEdge:15];
        [_btomBtn setTitle:@"马上咨询" forState:UIControlStateNormal];
        [_btomBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_btomBtn setBackgroundColor:Main_Color forState:UIControlStateNormal];
        _btomBtn.titleLabel.font = SYSTEMFONT(15);
        
        [_btomBtn handleControlEvent:UIControlEventTouchUpInside withBlock:^{
            [[GCPresenter shareInterface] phoneCall:@"400-088-1188"];
        }];
    }
    return _btomBtn;
}
-(TKL_BeautyDetailViewModel *)viewModel
{
    if (!_viewModel)
    {
        _viewModel=[TKL_BeautyDetailViewModel new];
    }
    return _viewModel;
}
#pragma mark - event
#pragma mark - method
-(void)initilization
{
    self.isGroup = YES;
    @WeakSelf;
    
    self.extendedLayoutIncludesOpaqueBars = YES;
    self.baseTable.contentInset = UIEdgeInsetsMake([self topShelterHeight], 0, [self bottomShelterHeight]+WFCGFloatY(45), 0);
    self.view.backgroundColor = Main_Color_BG;
    
    [self.view addSubview:self.baseTable];
    [self.view addSubview:self.btomBtn];
    [self.baseTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self.baseTable setSeparatorColor:Main_Color_BG];
    [self viewModelBand];
    
    self.baseTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [selfp reloadData];
        [selfp.baseTable.mj_header endRefreshing];
    }];
    [selfp reloadData];
}
-(void)viewModelBand
{
    @WeakSelf;
    GCBaseObservationModel* saleOber1=[GCBaseObservationModel new];
    saleOber1.keyPath=@"infoModel";
    saleOber1.observation=self.viewModel;
    saleOber1.handler = ^(NSString *keyPath) {
        selfp.navigationItem.title =selfp.viewModel.infoModel.name;
        [selfp.baseTable reloadData];
    };
    [self registObservation:saleOber1];
}
-(void)reloadListData
{
    NSMutableDictionary* para=[NSMutableDictionary new];
    [para setObject:@"iPhone" forKey:@"device"];
    [para setObject:@"济南" forKey:@"city"];
    [para setObject:_passID forKey:@"id"];
    [self.viewModel requestBeautyData:para];
}
-(void)reloadData
{
    [self reloadListData];
}
-(void)reloadView
{
    
}
#pragma mark - life

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initilization];
}
#pragma mark - delegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.viewModel.infoModel.images.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    @WeakSelf;
    static NSString* identify=@"ppPhonecell333";
    UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:identify];
    if (!cell)
    {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identify];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.backgroundColor=[UIColor whiteColor];
    }
    [cell.contentView removeAllSubviews];
    
    NSDictionary* dic=selfp.viewModel.infoModel.images[indexPath.row];
    UIImageView* lineIV=[UIImageView new];
    lineIV.width=SCREEN_WIDTH;
    lineIV.height=WFCGFloatY(200);
    lineIV.x=WFCGFloatX(0);
    lineIV.y=WFCGFloatY(0);
    lineIV.backgroundColor=Main_Color_BG;
    [cell.contentView addSubview:lineIV];
    [lineIV sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"url"]] placeholderImage:DefaultImage];
    lineIV.contentMode=UIViewContentModeScaleAspectFill;
    lineIV.layer.masksToBounds=YES;
    lineIV.tag=4000;
    
    __block UIImageView* pp=lineIV;
    [lineIV addTapGestureRecognizerWithDelegate:self Block:^(NSInteger tag) {
       
//        NSMutableArray* arr=[[NSMutableArray alloc] init];
//        NSMutableArray* sourImageArr=[[NSMutableArray alloc] init];
//
//        for (int j=0; j<selfp.viewModel.infoModel.images.count; j++)
//        {
//            NSDictionary* dic=selfp.viewModel.infoModel.images[j];
//            [arr addObject:[dic objectForKey:@"imgurl"]];
//            UIImageView* wwpp=[cell.contentView viewWithTag:4000];
//            [sourImageArr addObject:wwpp];
//        }
        
        
        PYPhotoBrowseView *photoBroseView = [[PYPhotoBrowseView alloc] init];
        photoBroseView.imagesURL = @[[dic objectForKey:@"url"]];
        photoBroseView.currentIndex = 0;
        photoBroseView.sourceImgageViews=@[pp];
        [photoBroseView show];
    }];
    
    UIView* view=[UIView new];
    view.backgroundColor=[UIColor blackColor];
    view.alpha=0.4;
    view.x=0;
    view.y=WFCGFloatY(160);
    view.width=SCREEN_WIDTH;
    view.height=WFCGFloatY(40);
    [lineIV addSubview:view];
    
    UILabel* titleLab=[UILabel new];
    titleLab.x=WFCGFloatX(0);
    titleLab.y=WFCGFloatY(160);
    titleLab.width=SCREEN_WIDTH;
    titleLab.height=WFCGFloatY(40);
    titleLab.textColor=[UIColor whiteColor];
    titleLab.font=SYSTEMFONT(15);
    titleLab.numberOfLines=2;
    [cell.contentView addSubview:titleLab];
    titleLab.text=[dic objectForKey:@"remark"];
    titleLab.textAlignment=NSTextAlignmentCenter;
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return WFCGFloatY(210);
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    view.backgroundColor=[UIColor whiteColor];
    
    UILabel* titleLab=[UILabel new];
    titleLab.x=WFCGFloatX(0);
    titleLab.y=WFCGFloatY(0);
    titleLab.width=WFCGFloatX(375);
    titleLab.height=WFCGFloatY(50);
    titleLab.textColor=HEXCOLOR(@"#333333");
    titleLab.font=SYSTEMFONT(18);
    titleLab.numberOfLines=2;
    [view addSubview:titleLab];
    titleLab.text=[NSString stringWithFormat:@"%@\n第一期",self.viewModel.infoModel.name];
    titleLab.textAlignment=NSTextAlignmentCenter;
    
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
     return WFCGFloatY(50);
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView* view=[UIView new];
    view.backgroundColor=[UIColor whiteColor];

    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
}
@end


/*
 11111111111111111111111111111111111111001111111111111111111111111
 11111111111111111111111111111111111100011111111111111111111111111
 11111111111111111111111111111111100001111111111111111111111111111
 11111111111111111111111111111110000111111111111111111111111111111
 11111111111111111111111111111000000111111111111111111111111111111
 11111111111111111111111111100000011110001100000000000000011111111
 11111111111111111100000000000000000000000000000000011111111111111
 11111111111111110111000000000000000000000000000011111111111111111
 11111111111111111111111000000000000000000000000000000000111111111
 11111111111111111110000000000000000000000000000000111111111111111
 11111111111111111100011100000000000000000000000000000111111111111
 11111111111111100000110000000000011000000000000000000011111111111
 11111111111111000000000000000100111100000000000001100000111111111
 11111111110000000000000000001110111110000000000000111000011111111
 11111111000000000000000000011111111100000000000000011110001111111
 11111110000000011111111111111111111100000000000000001111100111111
 11111111000001111111111111111111110000000000000000001111111111111
 11111111110111111111111111111100000000000000000000000111111111111
 11111111111111110000000000000000000000000000000000000111111111111
 11111111111111111100000000000000000000000000001100000111111111111
 11111111111111000000000000000000000000000000111100000111111111111
 11111111111000000000000000000000000000000001111110000111111111111
 11111111100000000000000000000000000000001111111110000111111111111
 11111110000000000000000000000000000000111111111110000111111111111
 11111100000000000000000001110000001111111111111110001111111111111
 11111000000000000000011111111111111111111111111110011111111111111
 11110000000000000001111111111111111100111111111111111111111111111
 11100000000000000011111111111111111111100001111111111111111111111
 11100000000001000111111111111111111111111000001111111111111111111
 11000000000001100111111111111111111111111110000000111111111111111
 11000000000000111011111111111100011111000011100000001111111111111
 11000000000000011111111111111111000111110000000000000011111111111
 11000000000000000011111111111111000000000000000000000000111111111
 11001000000000000000001111111110000000000000000000000000001111111
 11100110000000000001111111110000000000000000111000000000000111111
 11110110000000000000000000000000000000000111111111110000000011111
 11111110000000000000000000000000000000001111111111111100000001111
 11111110000010000000000000000001100000000111011111111110000001111
 11111111000111110000000000000111110000000000111111111110110000111
 11111110001111111100010000000001111100000111111111111111110000111
 11111110001111111111111110000000111111100000000111111111111000111
 11111111001111111111111111111000000111111111111111111111111100011
 11111111101111111111111111111110000111111111111111111111111001111
 11111111111111111111111111111110001111111111111111111111100111111
 11111111111111111111111111111111001111111111111111111111001111111
 11111111111111111111111111111111100111111111111111111111111111111
 11111111111111111111111111111111110111111111111111111111111111111
 
 
 */
